package com.example.cloudmusicserve.service;

import com.example.cloudmusicserve.dao.UserDao;
import com.example.cloudmusicserve.entity.User;
import com.example.cloudmusicserve.entity.UserMessage;
import com.example.cloudmusicserve.entity.UserUpdataMsg;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * @description: UserSerivce
 * @author: xiaoyuan
 * @time: 2023/5/27
 */
@Service
public class UserSerivce {

    //导入UserDao
    @Resource
    UserDao userDao;

    //查找用户的全部信息
    public List<UserMessage> getAll(){
        return userDao.getAll();
    }

    //查看该用户是否存在
    public Integer getByNameAndPassword(User user){
        if (userDao.queryByUsername(user)==0){
            return 2;
        }else {
            return userDao.queryUser(user);
        }
    }

    //注册用户
    public Integer addUser(User user){
        if (userDao.queryByUsername(user)==0){
            return userDao.addUser(user);
        }else {
            return 0;
        }
    }

    //通过用户名获取全部信息
    public UserMessage getByUsernameOfMsg(String username){
        return userDao.queryByUsernameOfMsg(username);
    }

    //更新用户信息
    public Integer updateUserMessage(UserUpdataMsg updataMsg){
        return userDao.updateUserMsg(updataMsg);
    }

}
